﻿using BJ.AuthEntity;
using Syspetro.Core.AppDeal;
using Syspetro.Core.CommandBus;
using Syspetro.Core.SysInterface;

namespace BJ.AuthDomain.Commands
{
    /// <summary>
    /// 校验验证码
    /// </summary>
    public class VerifyCodeCommand : Command
    {
        public AccountType AccountType { get; set; }
        public string Account { get; set; }
        public string Code { get; set; }
    }
    public interface IVerifyCodeCommandHandler : ICommandHandler<VerifyCodeCommand>, ITransientService
    {

    }
    public class VerifyCodeCommandHandler : CommandHandler<VerifyCodeCommand>, IVerifyCodeCommandHandler
    {
        readonly ICommandBus _command;
        public VerifyCodeCommandHandler(ICommandBus command)
        {
            _command = command;
        }
        public override SpActionResult<string> Execute(VerifyCodeCommand command)
        {
            var res = command.AccountType switch
            {
                AccountType.Email => _command.Send(new EmailVerifyCommand { Email = command.Account,  Captcha = command.Code }),
                AccountType.SMS => _command.Send(new SMSVerifyCommand { Phone = command.Account,  Captcha = command.Code }),
                _ => new SpActionResult { Success = false, Msg = "类型错误" },
            };
            return res.Get();
        }
    }
}
